package com.pcbly.web.action.timesheet;

import com.pcbly.web.action.BaseAction;
import com.pcbly.web.bean.timesheet.TimesheetReviewerBean;
import com.pcbly.web.business.timesheet.TimesheetReviewerService;

public class TimesheetReviewerAction extends BaseAction<TimesheetReviewerBean> {

	/**
	 * 
	 */
	private static final long serialVersionUID = -1077568283466013897L;

	protected TimesheetReviewerService timesheetService;

	public void setTimesheetReviewerService(
			TimesheetReviewerService timesheetService) {
		this.timesheetService = timesheetService;
	}

	private TimesheetReviewerBean timesheet;

	public TimesheetReviewerBean getTimesheetReviewer() {
		return timesheet;
	}

	public void setTimesheetReviewer(TimesheetReviewerBean timesheet) {
		this.timesheet = timesheet;
	}

	public String view() throws Exception {
		timesheet = timesheetService.getTimesheetReviewerBeanById(getId());
		return super.view();
	}

	public String update() throws Exception {
		timesheet = timesheetService.getTimesheetReviewerBeanById(getId());
		return super.update();
	}

	public String index() throws Exception {
		return super.index();
	}

	public String add() throws Exception {
		return super.add();
	}

	public String save() throws Exception {
		if (log.isDebugEnabled()) {
			log.debug("login save..........");
			log.debug(timesheet.getId());
		}
		try {
			if (timesheet.getId() == null || "".equals(timesheet.getId())) {// new
				timesheetService.saveTimesheetReviewerBean(timesheet);
				addActionMessage(getText("entity.saved"));
			} else {// update
				timesheetService.updateTimesheetReviewerBean(timesheet);
				addActionMessage(getText("entity.updated"));
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return super.save();
	}

	public String dwrSave(TimesheetReviewerBean bean) throws Exception {
		if (log.isDebugEnabled()) {
			log.debug("login save..........");
			log.debug(bean.getId());
		}
		try {
			if (bean.getId() == null || "".equals(bean.getId())) {// new
				timesheetService.saveTimesheetReviewerBean(bean);
			} else {// update
				timesheetService.updateTimesheetReviewerBean(bean);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return super.dwrBaseSave(bean.getId());
	}

	public String delete() throws Exception {
		if (log.isDebugEnabled()) {
			log.debug("login delete..........");
			log.debug(getId());
		}
		if (getId().indexOf(",") >= 0) {
			timesheetService.removeTimesheetReviewerBeanByIds(getId());
		} else {
			timesheetService.removeTimesheetReviewerBeanById(getId());
		}
		return super.delete();
	}

	public String dwrDelete(String id) throws Exception {
		if (log.isDebugEnabled()) {
			log.debug("login delete..........");
			log.debug(id);
		}
		if (id.indexOf(",") >= 0) {
			timesheetService.removeTimesheetReviewerBeanByIds(id);
		} else {
			timesheetService.removeTimesheetReviewerBeanById(id);
		}
		return super.dwrBaseDelete(id);
	}

}